import {
    queryUrl
} from '../utils/util'

Component({
    data: {
        selected: 0,
        list: [{
            pagePath: "/pages/homePage/index",
            iconPath: "/static/images/tabbar-homePage.png",
            selectedIconPath: "/static/images/tabbar-homePage-active.png",
            text: "首页"
        }, {
            pagePath: "/pages/charge/charge",
            iconPath: "/static/images/tabbar-chongdian.png",
            selectedIconPath: "/static/images/tabbar-chongdian-active.png",
            text: "充电"
        }, {
            pagePath: "0",
            iconPath: "/static/images/tabbar-center.png",
            text: "扫一扫"
        }, {
            pagePath: "1",
            iconPath: "/static/images/tabbar-haitaoyouxuan.png",
            selectedIconPath: "/static/images/tabbar-haitaoyouxuan-active.png",
            text: "购物车"
        }, {
            pagePath: "/pages/my/index",
            iconPath: "/static/images/tabbar-my.png",
            selectedIconPath: "/static/images/tabbar-my-active.png",
            text: "我的"
        }]
    },
    attached() {},
    methods: {
        switchTab(e) {
            const data = e.currentTarget.dataset
            const url = data.path;
            if (url == 0) {
                wx.scanCode({
                    success: function (res) {
                        console.log(queryUrl(res.result));
                        const terminal_no = queryUrl(res.result).terminal_no;
                        wx.navigateTo({
                            url: '/pages/advancePayment/index?terminal_no=' + terminal_no,
                        })
                    }
                })
            }
            if (url == 1) {
                wx.navigateTo({
                  url: '/pages/businessTalkmy/index',
                })
                // wx.navigateToMiniProgram({
                //     appId: 'wxf02b6affdf44fe96',
                //     path: 'pages/cart/index',
                //     envVersion: 'release', 
                //     success(res) {
                //       console.log("跳转小程序成功！",res);
                //     } 
                // })
                return;
            }
            wx.switchTab({
                url
            })
            this.setData({
                selected: data.index
            })
        }
    }
})